package com.victor.handler;

import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.victor.utils.Msg;

/**
 * 	系统异常拦截器404,500
 * 
 * @param req
 * @param resp
 * @param e
 * @return
 * @throws Exception
 */
//@ControllerAdvice
public class GlobalExceptionHandler {
	private Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);

//	@ExceptionHandler(value = Exception.class)
//	@ResponseBody
	public Msg defaultErrorHandler(HttpServletRequest req, Exception e) throws Exception {
		logger.error("", e);
		Msg fail = Msg.fail(e.getMessage());
		if (e instanceof org.springframework.web.servlet.NoHandlerFoundException) {
			Msg.fail("404");
		} else {
			Msg.fail("500");
		}
		return fail;
	}
}
